package com.exahq.controller;


import com.exahq.common.lang.Result;
import com.exahq.entity.Companydata;
import com.exahq.entity.Companytype;
import com.exahq.entity.Industry;
import com.exahq.service.CompanytypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lhq
 * @since 2021-02-02
 */
@RestController
@RequestMapping("/companytype")
public class CompanytypeController {
    @Autowired
    CompanytypeService companytypeService;

    /**
     * 查询所有信息
     * @return
     */
    @RequestMapping("/finaAll")
    public Result fianall(){
        List<Companytype> list = companytypeService.list();
        return Result.succ(list);
    }
    /**
     * 详情查询
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result detail(@PathVariable(name = "id") Integer id) {
        Companytype companytype = companytypeService.getById(id);
        return Result.succ(companytype);
    }
    /**
     * 删除
     * @param id
     * @return
     */
    @GetMapping("/del/{id}")
    public Result del(@PathVariable(name = "id") Integer id) {
        return Result.succ( companytypeService.delete(id));
    }

    /**
     * 增加/修改
     * @param companytype
     * @return
     */
    @PostMapping("saveEdit")
    public Result saveEdit(@RequestBody Companytype companytype){
        if (companytype!=null && !companytype.equals("")){
            if (companytype.getTid() == null){
                boolean b = companytypeService.save(companytype);
                if (b){
                    return Result.succ("新添成功",b);
                }
            }else {
                if (companytypeService.saveOrUpdate(companytype))
                    return Result.succ("修改成功",companytypeService.saveOrUpdate(companytype));
            }
        }
        return Result.succ(null);
    }
}
